package com.zhz.lib.project.ibatis.dao.libnews.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.zhz.lib.project.ibatis.dao.libnews.LibnewsDAO;
import com.zhz.lib.project.ibatis.domain.libnews.Libnews;
import com.zhz.project.common.util.alibaba.ArrayUtil;
import com.zhz.project.common.util.alibaba.StringUtil;

/**
 * @author LiWei <a href="mailto:liwei2672@gmail.com">liwei2672@gmail.com</a>
 * @version 创建时间：2010-5-12 下午09:42:16
 * 
 */
public class LibnewsDAOImpl extends SqlMapClientDaoSupport implements LibnewsDAO {
    private static Logger logger = Logger.getLogger(LibnewsDAOImpl.class);

    public Libnews getLibnewsById(String id) {
        return (Libnews) getSqlMapClientTemplate().queryForObject("getLibnewsById", id);
    }

    @SuppressWarnings("unchecked")
    public List<Libnews> getLatestLibnewsBySortType(int firstResult, int maxResults, String sortType) {
        Map map = new HashMap<String, Integer>();
        map.put("sortType", ArrayUtil.toList(StringUtil.split(sortType, ",")));
        map.put("firstResult", firstResult);
        map.put("maxResults", maxResults);
        List list = null;
        try {
            list = getSqlMapClientTemplate().queryForList("getLatestLibnewsBySortType", map);
        } catch (DataAccessException e) {
            logger.error("getLatestLibnewsBySortType发生异常", e);
        }
        return list;
    }

    @SuppressWarnings("unchecked")
    public void hitPlusOne(String id) {
        Map map = new HashMap<String, Integer>();
        map.put("libnewsID", id);
        getSqlMapClientTemplate().update("hitPlusOne", map);
    }

}
